package com.fescoservice.controller;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.fescoservice.model.BBS;
import com.fescoservice.model.BBSId;
import com.fescoservice.service.CategoryService;

@Controller
@RequestMapping("/action/MainHome.htm")

public class MainHomeController {
	private static final Logger log = Logger.getLogger(MainHomeController.class);
	
	@Autowired
	private CategoryService categoryService;

	@RequestMapping(params="cmd=setLanguage")
	public String setLanguage(ModelMap map, HttpServletRequest request){		
		String lang =(String)request.getParameter("language");
		if(null==lang || lang.equals("")) lang=(String)request.getLocale().getLanguage();
		request.getSession().setAttribute("userLanguage",lang);
		log.debug("~~~~~~~~language~~~~~~~~"+lang);
		return "mainhome";
	}
	
	@RequestMapping(params="cmd=add")
	public String addBBS(ModelMap map, HttpServletRequest request){		
		String boardcode1 =(String)request.getParameter("boardcode1");
		String boardcode2 =(String)request.getParameter("boardcode2");
		String boardcode3 =(String)request.getParameter("boardcode3");
		String title =(String)request.getParameter("title");
		String content =(String)request.getParameter("content");
		String sFile ="";
		BBSId bbsId = new BBSId(boardcode1,boardcode2,boardcode3,1L);
		BBS bbs = new BBS(bbsId);
		bbs.setTitle(title);
		//categoryService.saveBBS(bbs,content,sFile);
		return "mainhome";
	}
}
